package Arrays.YiChang.itheima.lianxi;

public class Students {
    private String name;
    private int age;
    private double math;//数学成绩
    private double chinese;//语文成绩
    private double Engilsh;//英语成绩

    public Students(String name, int age, double math, double chinese, double engilsh) {
        this.name = name;
        this.setAge(age);
        this.math = validateScore(math);
        this.chinese = validateScore(chinese);
        Engilsh = validateScore(engilsh);
    }

    public Students() {
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) throws RuntimeException {
        if (age>=0 && age<=120){
            this.age = age;
        }else {
            throw new RuntimeException("输入错误需要0-120之间的年龄");
        }
    }

    public double getMath() {
        return math;
    }

    public void setMath(double math) throws StudentScoreException {
        this.math = validateScore(math);
    }

    public double getChinese() {
        return chinese;
    }

    private double validateScore(double score) throws StudentScoreException {
        if (score>=0 && score <= 100){
            return score;
        }else {
            throw new StudentScoreException("成绩必须在0-100之间");
        }
    }

    public void setChinese(double chinese) {
        this.chinese=validateScore(chinese);
    }

    public double getEngilsh() {
        return Engilsh;
    }

    public void setEngilsh(double engilsh) throws StudentScoreException {
       this.Engilsh = validateScore(engilsh);
    }

    @Override
    public String toString() {
        return "Students{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", math=" + math +
                ", chinese=" + chinese +
                ", Engilsh=" + Engilsh +
                '}';
    }
}
